package com.iotstudio.embeddedcloudplatform.shiro.Filter;

import org.apache.shiro.web.filter.AccessControlFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

/**
 * 跨域访问拦截器
 * @author BeFondOfTaro
 * Created at 23:15 2018/4/10
 */
public class CorsFilter extends AccessControlFilter {

    @Override
    protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) throws Exception {
        //跨域设置
        ((HttpServletResponse)servletResponse).setHeader("Access-Control-Allow-Origin", "*");
        return true;
    }

    @Override
    protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
        return false;
    }
}
